import { defineStore } from "pinia";
import { getHomeHotSuggests, getHomeCategories, getHouseList } from "@/services";

const useHomeStore = defineStore('home', {
  state: () => ({
    hotSuggests: [],
    categories: [],

    currentPage: 1,
    houseList: []
  }),
  actions: {
    async fetchHotSuggests() {
      const res = await getHomeHotSuggests()
      this.hotSuggests = res.data
    },
    async fetchCategories() {
      const res = await getHomeCategories()
      // console.log(res)
      this.categories = res.data
    },
    async fetchHouseList() {
      const res = await getHouseList(this.currentPage)
      // console.log(res)
      this.houseList.push(...res.data)
      this.currentPage ++
    }
  }
})

export default useHomeStore